﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Churchtoolkit.Utils.Authentication;
using Churchtoolkit.Utils.MVP;
using Churchtoolkit.Web.Shell.Views;
using Churchtoolkit.DataAccess.Repositories;
using Churchtoolkit.DataAccess.Entities;
using Churchtoolkit.DataAccess.Common;
using Churchtoolkit.Utils.EmailProvider;
using Churchtoolkit.Web.Shell.Services;

namespace Churchtoolkit.Web.Shell.Presenters
{
    public class ForgetPasswordPresenter : Presenter<IForgetPasswordView>
    {
        public MembersRepository _member;
        public IAuthentication _authentication;
        public IEmailProvider _emailProvider;
        private Members member;
        public ForgetPasswordPresenter(MembersRepository memberRepository, IAuthentication authentication,IEmailProvider emailProvider)
        {
            _member = memberRepository;
            _authentication = authentication;
            _emailProvider = emailProvider;
        }
        public bool AvailableMail(string mail)
        {
            EntityResult<Members> members = _member.Find(m => m.Email = mail);
            if (members.RowsCount == 0)
            {
                return false;
            }
            member=members.Single();
            return true;
        }
        public void SendPasswordMail()
        {
            _emailProvider.SendMail(member.Email, "0002", member.FirstName, member.Password);
        }

    }
}
